package com.innovations.inn.service.impl;

import com.innovations.common.utils.uuid.IdGeneratorSnowflake;
import com.innovations.inn.domain.OutcomesTagRelate;
import com.innovations.inn.mapper.OutcomesTagRelateMapper;
import com.innovations.inn.service.IOutcomesTagRelateService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 成果标签对应Service业务层处理
 *
 * @author dp
 * @date 2024-08-10
 */
@Service
public class OutcomesTagRelateServiceImpl implements IOutcomesTagRelateService {
    @Autowired
    private OutcomesTagRelateMapper outcomesTagRelateMapper;
    @Autowired
    private IdGeneratorSnowflake idGeneratorSnowflake;

    /**
     * 查询成果标签对应
     *
     * @param relateId 成果标签对应主键
     * @return 成果标签对应
     */
    @Override
    public OutcomesTagRelate selectOutcomesTagRelateByRelateId(Long relateId) {
        return outcomesTagRelateMapper.selectOutcomesTagRelateByRelateId(relateId);
    }

    /**
     * 查询成果标签对应列表
     *
     * @param outcomesTagRelate 成果标签对应
     * @return 成果标签对应
     */
    @Override
    public List<OutcomesTagRelate> selectOutcomesTagRelateList(OutcomesTagRelate outcomesTagRelate) {
        return outcomesTagRelateMapper.selectOutcomesTagRelateList(outcomesTagRelate);
    }

    /**
     * 新增成果标签对应
     *
     * @param outcomesTagRelate 成果标签对应
     * @return 结果
     */
    @Override
    public int insertOutcomesTagRelate(OutcomesTagRelate outcomesTagRelate) {
        return outcomesTagRelateMapper.insertOutcomesTagRelate(outcomesTagRelate);
    }

    /**
     * 新增成果标签对应
     *
     * @param outcomesTagRelatelist 成果标签对应
     * @return 结果
     */
    @Override
    public int insertOutcomesTagRelate(List<OutcomesTagRelate> outcomesTagRelatelist) {
        try {
            outcomesTagRelatelist.forEach(outcomesTagRelate -> {
                outcomesTagRelateMapper.insertOutcomesTagRelate(outcomesTagRelate);
            });
        } catch (Exception e) {
            return 0;
        }
        return 1;
    }

    /**
     * 修改成果标签对应
     *
     * @param outcomesTagRelate 成果标签对应
     * @return 结果
     */
    @Override
    public int updateOutcomesTagRelate(OutcomesTagRelate outcomesTagRelate) {
        return outcomesTagRelateMapper.updateOutcomesTagRelate(outcomesTagRelate);
    }

    /**
     * 批量删除成果标签对应
     *
     * @param relateIds 需要删除的成果标签对应主键
     * @return 结果
     */
    @Override
    public int deleteOutcomesTagRelateByRelateIds(Long[] relateIds) {
        return outcomesTagRelateMapper.deleteOutcomesTagRelateByRelateIds(relateIds);
    }

    /**
     * 删除成果标签对应信息
     *
     * @param relateId 成果标签对应主键
     * @return 结果
     */
    @Override
    public int deleteOutcomesTagRelateByRelateId(Long relateId) {
        return outcomesTagRelateMapper.deleteOutcomesTagRelateByRelateId(relateId);
    }

    /**
     * 删除成果标签对应信息--根据成果标识
     *
     * @param researchOutcomesId 成果标识
     * @return 结果
     */
    @Override
    public int deleteOutcomesTagRelateByResearchOutcomesId(Long researchOutcomesId) {
        return outcomesTagRelateMapper.deleteOutcomesTagRelateByResearchOutcomesId(researchOutcomesId);
    }

    /**
     * 实体数据补全
     *
     * @param outcomesTagRelate 实体
     * @param userId            用户id
     * @param crateType         创建类型 1：新增 2：修改
     */
    @Override
    public void completeData(OutcomesTagRelate outcomesTagRelate, Long userId, Integer crateType) {
        //主键
        if (outcomesTagRelate.getRelateId() == null || "".equals(outcomesTagRelate.getRelateId())) {
            outcomesTagRelate.setRelateId(idGeneratorSnowflake.nextId());
        }
    }

    /**
     * 查询成果标签对应-根据科研成果标识
     *
     * @param researchOutcomesId 成果标识
     * @return 成果标签对应
     */
    @Override
    public List<OutcomesTagRelate> selectOutcomesTagRelateByOutcomesId(Long researchOutcomesId) {
        return outcomesTagRelateMapper.selectOutcomesTagRelateByOutcomesId(researchOutcomesId);
    }
}
